<?php
namespace Admin\Controller;
/**
 * 担保交易 控制器
 */
class DuobaoController extends AdminController{

    /**
     * 担保交易列表 所有用户的
     */
    public function index($coin_type = 0,$status = 0) {

        $this->assign("coins",M("Coin")->select());

        $where = array();

		if ($coin_type != 0) {
			$where['coin_type'] = $coin_type;
        }
        if ($status != 0) {
			$where['status'] = $status;
		}
		
		

		$count = M('SecuredTransaction')->where($where)->count();
		
		
		$Page = new \Think\Page($count, 15);
		$show = $Page->show();
		$list = M('SecuredTransaction')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();

		foreach ($list as $k => $v) {
			$list[$k]['username'] = username($v['user_id']);
			$list[$k]['roleName'] = $v['role'] == 1?"买家":"卖家";
            $list[$k]['coinTypeName'] = M("Coin")->find($v['coin_type'])['title'];
            $list[$k]['statusTitle'] = $v['status']==1?"交易中":$v['status']==2?"交易完成":"交易拒绝";
            $agencyFeePayType = $v['agency_fee_pay_type'];
			$list[$k]['agency_fee_pay_type_name'] = $agencyFeePayType == 1?"买家支付":($agencyFeePayType == 2?"卖家支付":($agencyFeePayType==3?"双方平摊":"双向收取（公众号）"));
		}
		$this->assign('list', $list);
		$this->assign('count', $count);
		$this->assign('page', $show);
		$this->display();
    }
}
